#ifndef HELPER_H
#define HELPER_H
#include <cmath>

struct Complex
{
    double          re;
    double          im;

    Complex()
    {
        re = 0.0;
        im = 0.0;
    }

    Complex(double _re, double _im)
    {
        re = _re;
        im = _im;
    }

    float GetPhase()            // Argument
    {
        return (float) atan(im / re);
    }

    float GetMagnitude()        // Modulus
    {
        return (float) sqrt(re * re + im * im);
    }

    void Conjugate()
    {
        im *= -1.0;
    }

    Complex operator+ (Complex &_cx)
    {
        return Complex(re + _cx.re, im + _cx.im);
    }

    Complex operator- (Complex &_cx)
    {
        return Complex(re + (-1.0 * _cx.re), im + (-1.0 * _cx.im));
    }

    Complex operator* (Complex &_cx)
    {
        return Complex(re * _cx.re, re * _cx.im + im * _cx.re + ((-1.0) * (im * _cx.im)));
    }

    Complex operator/ (Complex &_cx)
    {
        Complex conj = _cx;
        Complex numerator;
        Complex denominator;
        conj.Conjugate();
        numerator = *this * conj;
        denominator = _cx * conj;

        return Complex(numerator.re / denominator.re, numerator.im / denominator.re);
    }

    Complex DivByNumber(double _val)           // Check if it's correct!
    {
        return Complex(re / _val, im / _val);
    }

    Complex MultByNumber(double _val)           // Check if it's correct!
    {
        return Complex(re * _val, im * _val);
    }
};

#endif // HELPER_H
